package utilities
{
	import org.flixel.*;
	
	/**
	 * ...
	 * @author Andrew Lau
	 */
	public class TextBoxList extends FlxGroup
	{
		private var target:FlxSprite;
		private var delay:Number;
		private var loop:Boolean;
		private var list:Array;
		
		public function TextBoxList(target:FlxSprite, delay:Number = 0.0, loop:Boolean = false)
		{
			this.target = target;
			this.delay = delay;
			this.loop = loop;
			this.list = new Array();
		}
		
		public function addText(name:String, phrase:String, width:int = 110, lifetime:Number = 1.5):TextBox
		{
			var text:TextBox = new TextBox(name, target, phrase, width, lifetime);
			list.push(text);
			add(text);
			
			return text;
		}
		
		public function changeText(name:String, phrase:String):void
		{
			for (var i:uint = 0; i < list.length; i++)
			{
				var textBox:TextBox = list[i];
				if (textBox.name == name)
				{
					textBox.setText(phrase);
					textBox.init();
				}
			}
		}
		
		override public function destroy():void
		{
			Registry.animations.remove(this);
			
			super.destroy();
		}
		
		public function play(name:String):void
		{
			Registry.animations.add(this);
			for (var i:uint = 0; i < list.length; i++)
			{
				var textBox:TextBox = list[i];
				if (textBox.name == name)
				{
					if (textBox.finished || !textBox.exists)
					{
						textBox.init();
					}
				}
			}
		}
		
		override public function update():void
		{
			super.update();
			//if (list.length != 0 && (list[list.length - 1] as TextBox).finished)
			//{
			//list.pop();
			//if (list.length > 0)
			//{
			//add(list[list.length - 1]);
			//currentEnemy.active = true;
			//}
			//}
		}
	
	}

}